﻿using System;
using System.Data;
using System.Data.OleDb;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class admin_SeeUsers : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Session["name"] == null)
            {
                Response.Write("<script>alert('非法登录!!!');window.top.location='../Login.aspx';</script>");
                return;
            }
            else
            {
                BindUsers();
            }
           
        }
    }
    //自动编号
    protected void gv_users_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowIndex != -1)
        {
            int sortid = e.Row.RowIndex + 1;
            e.Row.Cells[0].Text = sortid.ToString();
        }
    }

    //绑定用户信息
    protected void BindUsers()
    {
        string selectstr = "select * from tb_admin";
        DataTable dt = new DataTable();
        dt = OleDbHelper.GetDataTable(selectstr);
        gv_users.DataSource = dt;
        gv_users.DataBind();
    }


    //删除用户
    protected void lb_delete_Click(object sender, EventArgs e)
    {
        LinkButton btn = (LinkButton)sender;
        int id = int.Parse(btn.CommandArgument.ToString());
        string deletestr = "delete from tb_admin where a_id=@a_id";
        OleDbParameter[] param = { 
                                     new OleDbParameter("a_id",id)
                                 };
        int flag = OleDbHelper.ExecuteNonSql(deletestr, param);
        if (flag > 0)
        {
            Page.ClientScript.RegisterStartupScript(GetType(), "提示", "<script>alert('删除成功！')</script>");
            BindUsers();
        }
        else
        {
            Page.ClientScript.RegisterStartupScript(GetType(), "提示", "<script>alert('删除失败！')</script>");
        }
    }
}